﻿using System;
using System.Collections.Generic;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using YJKArch.Utils;
using YJKDragCurveJig;

namespace YJKArch.DormantWindow
{
	public class DragJig
	{
		public static bool PickLeftBottomPosition(ExternalCommandData commandData, XYZ dormantDirection, double dormantWidth, double maxRidgeHeight, double wallHeight, double slopeAngle, ref XYZ ptPos)
		{
			XYZ xyz = Geometry.RotateTo(dormantDirection, -Math.PI*.5, XYZ.BasisZ).Normalize();
			XYZ zero = XYZ.Zero;
			XYZ xyz2 = zero + xyz * dormantWidth / 2.0;
			XYZ xyz3 = zero + xyz * dormantWidth;
			double num = maxRidgeHeight / Math.Tan(slopeAngle);
			double num2 = wallHeight / Math.Tan(slopeAngle);
			XYZ xyz4 = zero + dormantDirection * num2;
			XYZ xyz5 = xyz2 + dormantDirection * num;
			XYZ endPoint = xyz3 + dormantDirection * num2;
			List<JigEdgeInfo> list = new List<JigEdgeInfo>();
			JigEdgeInfo item = new JigEdgeInfo(zero, xyz3, 0.0);
			list.Add(item);
			JigEdgeInfo item2 = new JigEdgeInfo(zero, xyz4, 0.0);
			list.Add(item2);
			JigEdgeInfo item3 = new JigEdgeInfo(xyz3, endPoint, 0.0);
			list.Add(item3);
			JigEdgeInfo item4 = new JigEdgeInfo(xyz2, xyz5, 0.0);
			list.Add(item4);
			JigEdgeInfo item5 = new JigEdgeInfo(xyz4, xyz5, 0.0);
			list.Add(item5);
			JigEdgeInfo item6 = new JigEdgeInfo(xyz5, endPoint, 0.0);
			list.Add(item6);
			List<JigTextInfo> textInfos = new List<JigTextInfo>();
			try
			{
				if (!DragCurveJigInterface.GetInsertPosition(commandData, list, false, textInfos, false, XYZ.Zero, ref ptPos))
				{
					return false;
				}
			}
			catch (Exception)
			{
				return false;
			}
			return true;
		}
	}
}
